<?php
/* Author: tbloc@cantho.gov.vn */
/* Created Date : 17-07-2014 10:10:51 */
class M_Nhan_vien{  
//Properties
private $NV_ID;
private $NV_HOTEN;
private $NV_EMAIL;
private $NV_SDT;
private $NV_USERNAME;
private $NV_PASSWORD;
private $NV_AVARTAR;
private $TK_ID;
//properties set get 
public function setNV_ID($NV_ID) 
{
	$this->NV_ID = $NV_ID;
}
public function getNV_ID()
{
	return $this->NV_ID;
}	        
public function setNV_HOTEN($NV_HOTEN) 
{
	$this->NV_HOTEN = $NV_HOTEN;
}
public function getNV_HOTEN()
{
	return $this->NV_HOTEN;
}	        
public function setNV_EMAIL($NV_EMAIL) 
{
	$this->NV_EMAIL = $NV_EMAIL;
}
public function getNV_EMAIL()
{
	return $this->NV_EMAIL;
}	        
public function setNV_SDT($NV_SDT) 
{
	$this->NV_SDT = $NV_SDT;
}
public function getNV_SDT()
{
	return $this->NV_SDT;
}	        
public function setNV_USERNAME($NV_USERNAME) 
{
	$this->NV_USERNAME = $NV_USERNAME;
}
public function getNV_USERNAME()
{
	return $this->NV_USERNAME;
}	        
public function setNV_PASSWORD($NV_PASSWORD) 
{
	$this->NV_PASSWORD = $NV_PASSWORD;
}
public function getNV_PASSWORD()
{
	return $this->NV_PASSWORD;
}	        
public function setNV_AVARTAR($NV_AVARTAR) 
{
	$this->NV_AVARTAR = $NV_AVARTAR;
}
public function getNV_AVARTAR()
{
	return $this->NV_AVARTAR;
}	        
public function setTK_ID($TK_ID) 
{
	$this->TK_ID = $TK_ID;
}
public function getTK_ID()
{
	return $this->TK_ID;
}	        
//crud methods
public function insert($db = null) {
	if ($db != null){
	$sql = "INSERT INTO `nhan_vien`(                        
			`NV_ID`, 
				`NV_HOTEN`, 
				`NV_EMAIL`, 
				`NV_SDT`, 
				`NV_USERNAME`, 
				`NV_PASSWORD`, 
				`NV_AVARTAR`, 
				`TK_ID` 
		)
	VALUES(
    		:NV_ID, 
	    		:NV_HOTEN, 
	    		:NV_EMAIL, 
	    		:NV_SDT, 
	    		:NV_USERNAME, 
	    		:NV_PASSWORD, 
	    		:NV_AVARTAR, 
	    		:TK_ID 
	    );";
	$parameters = array(
			":NV_ID", 
				":NV_HOTEN", 
				":NV_EMAIL", 
				":NV_SDT", 
				":NV_USERNAME", 
				":NV_PASSWORD", 
				":NV_AVARTAR", 
				":TK_ID" 
		);
    $values = array(  
            	$this->getNV_ID(), 
	            	$this->getNV_HOTEN(), 
	            	$this->getNV_EMAIL(), 
	            	$this->getNV_SDT(), 
	            	$this->getNV_USERNAME(), 
	            	$this->getNV_PASSWORD(), 
	            	$this->getNV_AVARTAR(), 
	            	$this->getTK_ID()
	    );
    $types = array(
   
                                    PDO::PARAM_INT,
                                                       PDO::PARAM_STR,
                                                       PDO::PARAM_STR,
                                                       PDO::PARAM_STR,
                                                       PDO::PARAM_STR,
                                                       PDO::PARAM_STR,
                                                       PDO::PARAM_STR,
                                                        PDO::PARAM_INT
                       );
	$lastInsertID = $db->executeNonQuery($sql, $parameters, $values, $types, true);
	$this->setNV_ID($lastInsertID);
    }
}
	
	public function delete($db = null) {
	    if ($db != null) {
	        $sql = "update `nhan_vien`
	                set `is_active`=0
	                where `NV_ID` = :NV_ID;";
	        $parameters = array(":NV_ID");
	        $values = array($this->getNV_ID());
	        $types = array(PDO::PARAM_INT);//Kiem tra lai kieu du lieu nhe
	        $result = $db->executeNonQuery($sql, $parameters, $values, $types);
	        return $result;
	    }
	}
	
	public function update($db = null) {
	        if ($db != null) {
	            $sql = "UPDATE `nhan_vien` SET 
			`NV_ID`=:NV_ID,
				`NV_HOTEN`=:NV_HOTEN,
				`NV_EMAIL`=:NV_EMAIL,
				`NV_SDT`=:NV_SDT,
				`NV_USERNAME`=:NV_USERNAME,
				`NV_PASSWORD`=:NV_PASSWORD,
				`NV_AVARTAR`=:NV_AVARTAR,
				`TK_ID`=:TK_ID
			WHERE `NV_ID` = :NV_ID;";
	            $parameters = array(
	        	":NV_ID",
		        	":NV_HOTEN",
		        	":NV_EMAIL",
		        	":NV_SDT",
		        	":NV_USERNAME",
		        	":NV_PASSWORD",
		        	":NV_AVARTAR",
		        	":TK_ID"
		        );	
	$values = array(  
	        	$this->getNV_ID(),
        	        	$this->getNV_HOTEN(),
        	        	$this->getNV_EMAIL(),
        	        	$this->getNV_SDT(),
        	        	$this->getNV_USERNAME(),
        	        	$this->getNV_PASSWORD(),
        	        	$this->getNV_AVARTAR(),
        	                $this->getTK_ID()      
        	);
    $types = array(
                                    PDO::PARAM_INT,
                                                       PDO::PARAM_STR,
                                                       PDO::PARAM_STR,
                                                       PDO::PARAM_STR,
                                                       PDO::PARAM_STR,
                                                       PDO::PARAM_STR,
                                                       PDO::PARAM_STR,
                                                       PDO::PARAM_INT
                       );
	$result = $db->executeNonQuery($sql, $parameters, $values, $types);
	return $result;
	        }
	 }
	 
	public function getByID($db = null) {
	if ($db != null) {
	$sql = "SELECT
			`NV_ID`,
				`NV_HOTEN`,
				`NV_EMAIL`,
				`NV_SDT`,
				`NV_USERNAME`,
				`NV_PASSWORD`,
				`NV_AVARTAR`,
				`TK_ID`
			FROM `nhan_vien` WHERE `NV_ID` = :NV_ID and `is_active`=1;";
	$parameters = array(":NV_ID");
	$values = array($this->getNV_ID());
	$types = array(PDO::PARAM_INT);//kiem tra lai kieu du lieu nhe
	$rows = $db->executeQuery($sql, $parameters, $values, $types);
	if ($rows != null) {
	$row = $rows->fetch();
		$this->setNV_ID($row->NV_ID);
		$this->setNV_HOTEN($row->NV_HOTEN);
		$this->setNV_EMAIL($row->NV_EMAIL);
		$this->setNV_SDT($row->NV_SDT);
		$this->setNV_USERNAME($row->NV_USERNAME);
		$this->setNV_PASSWORD($row->NV_PASSWORD);
		$this->setNV_AVARTAR($row->NV_AVARTAR);
		$this->setTK_ID($row->TK_ID);
	}
	return $this;
		}
	}
	
	public function getList($db = null) {
	if ($db != null) {
    $sql = "SELECT
			`NV_ID`,
				`NV_HOTEN`,
				`NV_EMAIL`,
				`NV_SDT`,
				`NV_USERNAME`,
				`NV_PASSWORD`,
				`NV_AVARTAR`,
				`TK_ID`
			FROM `nhan_vien` WHERE `is_active`=1;";
    $rows = $db->executeQuery($sql);
    $objects = array();
    if ($rows != null) {
    while ($row = $rows->fetch()) {
    $obj = new nhan_vien();
    	 $obj->setNV_ID($row->NV_ID);
		 $obj->setNV_HOTEN($row->NV_HOTEN);
		 $obj->setNV_EMAIL($row->NV_EMAIL);
		 $obj->setNV_SDT($row->NV_SDT);
		 $obj->setNV_USERNAME($row->NV_USERNAME);
		 $obj->setNV_PASSWORD($row->NV_PASSWORD);
		 $obj->setNV_AVARTAR($row->NV_AVARTAR);
		 $obj->setTK_ID($row->TK_ID);
		$objects[] = $obj;
    }
    return $objects;
    }
        }
    }
}
?>

